package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import connection.DbConnection;

public class addPollCreatorServlet extends HttpServlet {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2902283982236815056L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost (request, response);
	}
	
	public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		response.setCharacterEncoding("GBK");
		
		System.out.println("addPollCreatorServlet run");
		
		// Get parameters
		String selected_poll = request.getSession().getAttribute("selected_poll").toString();
		String poll_creator = request.getParameter("poll_creator");

		// Error checking
		System.out.println("selected_poll: "+selected_poll);
		System.out.println("poll_creator: "+poll_creator);
		
		// Add to user_poll
		DbConnection db = new DbConnection();
		String sql = "Insert into User_Poll Values ('"+poll_creator+"',"+selected_poll+","+selected_poll+")";
		System.out.println(sql);
		db.doInsert(sql);
		
		response.sendRedirect("assignUser.jsp");
	}
}
